package com.hqj.demo01;

/**
 * 类的继承练习
 * @author HQJ
 *  * 1、季节类Season
 *  * 属性name,count,price
 *  * name表示季节的名称，count为季节使用的电量，price为这个季节的电的单价
 *  * 提供合适的构造方法
 *  * 提供get/set方法
 *  * 方法calcEleFee()，计算电费，且返回(保留两位小数)。
 *  * 2、夏天类Summer 继承Season
 *  * 有属性add,
 *  * add表示补贴的电量(不计算电费)
 *  * 重写计算电费的方法，计算夏天的电费
 *  * 有方法swimming()游泳方法，简单输出语句
 *  * 3、冬天类Winter 继承Season
 *  * 有属性other
 *  * other表示电的损耗量(计算电费)
 *  * 重写计算电费的方法，计算冬天的电费
 *  * 有方法makeSnow()堆雪人方法，简单输出语句
 *  * 4、StringUtil工具类，方法sessonMethod(),参数季节对象
 *  *  根据参数获得电费及调用对应的娱乐方法。
 *  * 5、测试类
 *  * 测试StringUtil的sessonMethod的方法
 */
public class Exercise02 {
    public static void main(String[] args) {
        Season summer = new Summer("酷夏",1200,0.556,100);
        Season winter = new Winter("严冬",800,0.756,30);

        StringUtil su = new StringUtil();
        su.seasonMethod(summer);

        su.seasonMethod(winter);
    }
}
class Season{

    private String name;
    private double count;
    private double price;

    public Season(){}

    public Season(String name, double count, double price) {
        this.name = name;
        this.count = count;
        this.price = price;
    }

    public double calcEleFee(){
        return 0.0D;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getCount() {
        return count;
    }

    public void setCount(double count) {
        this.count = count;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}

class Summer extends Season{
    private int add;
    public Summer(){}

    public Summer(String name, double count, double price, int add) {
        super(name, count, price);
        this.add = add;
    }

    @Override
    public double calcEleFee() {
        return (this.getCount()-add)*this.getPrice();
    }

    public void swimming(){
        System.out.println("夏天游泳请小心!");
    }

    public int getAdd() {
        return add;
    }

    public void setAdd(int add) {
        this.add = add;
    }
}

class Winter extends  Season{
    private double other;

    public Winter(){}

    public Winter(String name, double count, double price, double other) {
        super(name, count, price);
        this.other = other;
    }

    @Override
    public double calcEleFee() {
        return (this.getCount()+this.getOther())*this.getPrice();
    }

    public void createSnow(){
        System.out.println("堆雪人，打雪仗");
    }

    public double getOther() {
        return other;
    }

    public void setOther(double other) {
        this.other = other;
    }
}
class StringUtil{

    public void seasonMethod(Season season){

        double eleFee = season.calcEleFee();
        System.out.println(season.getName()+"的电费消耗"+season.getCount()+"度,共计:"+eleFee+"￥。");
        if(season instanceof Summer){
            Summer summer = (Summer)season;
            summer.swimming();
        }else if(season instanceof Winter){
            Winter winter = (Winter)season;
            winter.createSnow();
        }

    }

}